package com.woniu.controller;

import com.woniu.entity.Book;
import com.woniu.service.BookService;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
@AllArgsConstructor
//@CrossOrigin(origins = "*")// 允许该类的所有接口跨域访问
public class BookController {
    private BookService bookService;

    @GetMapping("/queryAll")
    public ResponseData<?> queryAll(){
        List<Book> books = bookService.queryAll();
        return ResponseData.ok(books);
    }
    @GetMapping("/bookDetail/{id}")
    public ResponseData<?> queryDetail(@PathVariable("id") Integer id){
        Book books = bookService.queryBookById(id);
        if (books == null){
            return ResponseData.fail(ResponseEnum.SYS_BUSY);
        }
        return ResponseData.ok(books);
    }
}
